package cn.jiahui;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;

import com.demo.common.DemoConfig;
import com.demo.user.User;
import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;

import cn.jiahui.HibUtils;

public class JiahuiController  extends Controller{
	
	public void index(){
		renderJson("{'1':'2'}");
	}
	
	public void hartBeat(){
		renderText("heartBeat");
	}
	
	public void sendCommond(){
		int btnId = 1;
		int light = 1;
		btnId = getParaToInt("btnId", 1);
		light = getParaToInt("light",1);
		
		try {
			boolean flag = DemoConfig.liftService.setBtnState(btnId, light);
			if(flag){
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		renderText("{success}");
	}
	
	public void queryBtnState(){
		ArrayList<LiftBtnState> btnStateArry = DemoConfig.liftService.getBtnState();
		if(btnStateArry == null){
			renderText("{state:1, msg: lift not connected! queryBtnState()}");
			return;
		}
		String json = JsonKit.toJson(btnStateArry);
		System.out.println(json);
		renderText(json);
	}
	
	public void queryLiftState(){
		LiftState liftState= DemoConfig.liftService.getLiftState();
		if(liftState == null){
			renderText("{state:1, msg: lift not connected! queryLiftState()}");
			return;
		}
		String json = JsonKit.toJson(liftState);
		System.out.println(json);
		renderText(json);
	}
}

